import React, { useRef, useState,useEffect } from 'react';
import { StyleSheet, View, Text, Button ,} from 'react-native';
import { AsyncStorage } from 'react-native-async-storage/async-storage';

const Home = ({navigation}) => {
  const [sound, setSound] = useState();
  // 一进去就播放，相当于是背景音乐
  useEffect(async()=>{
    const { sound } = await Audio.Sound.createAsync(
      require('../assets/危险派对.mp3')
    );
    // setSound(sound);
    await sound.playAsync();
    // 跳走的时候是可以拿到111打印出来的，页面离开的时候可以拿到的事件
    navigation.addListener('blur',()=>{
      console.log('1111');
      // 离开页面就停止播放
      sound.pauseAsync();
    })
  })
  const storeData = async (value) => {
    try {
       await AsyncStorage.setItem('@storage_Key', value)
    } catch (e) {
       // saving error
    }
  }
  const getData = async () => {
    try {
      const value = await AsyncStorage.getItem('@storage_Key')
      if(value !== null) {
        // value previously stored
      }
    } catch(e) {
      // error reading value
    }
  }

  return <View style={{ width: '100%', height: 900 }}>
    <View style={{ height: 350 }}>
      {/* <Button title="Play Sound" onPress={playSound} /> */}
    </View>

  </View>
}
export default Home;